package com.swgk.core.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.animation.RotateAnimation;

import androidx.annotation.NonNull;

import com.airbnb.lottie.LottieAnimationView;
import com.swgk.core.R;
import com.swgk.core.customview.loadingView.JYBLoadingView;

/**
 * Created by LT on 2018/5/12.
 */
public class LoadingDialogNew extends Dialog {

    private static final String TAG = "LoadingDialog";

    private String mMessage;
    private int mImageId;
    private boolean mCancelable;
    private RotateAnimation mRotateAnimation;
    private LottieAnimationView lottieAnimationView;
    private Context mContext;

    public LoadingDialogNew(@NonNull Context context, String message, int imageId) {
        this(context, R.style.LoadingDialog, message, imageId, false);
    }

    public LoadingDialogNew(@NonNull Context context, int themeResId, String message, int imageId, boolean cancelable) {
        super(context, themeResId);
        mMessage = message;
        mImageId = imageId;
        mCancelable = cancelable;
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: ");
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_loading_new);
        setCancelable(mCancelable);

        JYBLoadingView loadView = findViewById(R.id.loadView);
        loadView.setLoadingText(mMessage);
    }

    public void setMessage(String msg) {
        mMessage = msg;
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }


    @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // 屏蔽返回键
            return mCancelable;
        }
        return super.onKeyDown(keyCode, event);
    }
}
